package com.ewzj.bigdata.mvp.ui.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewzj.bigdata.R;
import com.ewzj.bigdata.mvp.model.entity.resbean.TitleBean;
import com.jess.arms.utils.ArmsUtils;

import java.util.List;

/**
 * Author:zhangjing
 * Time:2018/2/1  下午12:57
 * Name: this is TabItemAdapter
 * Email:zhangjingworkmol@163.com
 */

public class TabItemAdapter extends BaseQuickAdapter<TitleBean,BaseViewHolder>{
    public TabItemAdapter(@Nullable List<TitleBean> data) {
        super(R.layout.item_titlebar, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TitleBean item) {
        TextView textView=helper.<TextView>getView(R.id.tv_tab);
        textView.setText(item.getTitle());
        if (item.isSelected()){
            textView.setSelected(true);
            Drawable drawable=ArmsUtils.getDrawablebyResource(mContext,R.drawable.green_connor5_line);
            drawable.setBounds(0, 0, 64, 10);
            textView.setCompoundDrawables(null, null, null,drawable );
        }else {
            textView.setSelected(false);
            textView.setCompoundDrawables(null, null, null, null);
        }
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (TitleBean titleBean:mData){
                    titleBean.setSelected(false);
                }
                item.setSelected(true);
                notifyDataSetChanged();
            }
        });
    }
}
